import prompt from '@system.prompt';
import router from '@system.router';
import http from '@ohos.net.http';
export default {
    data: {
        title: "world",
        user:{username:"",phone:"",password:""}
    },

    register()
    {
        let httpRequest = http.createHttp();
        httpRequest.request(
            "http://hjj.vaiwan.com/register",
            {
                method: 'POST', // 可选，默认为“GET”
                header: {
                    'Content-Type': 'application/json'
                },
                extraData: this.user,
                readTimeout: 60000, // 可选，默认为60000ms
                connectTimeout: 60000 // 可选，默认为60000ms
            },
            (err, data) => {
                if (!err) {
                    let result = JSON.parse(data.result);
                    if(result.code == 20000)
                    {
                        router.replace({
                            uri:"pages/login/login"
                        })
                    }
                    else
                    {
                        prompt.showToast({message:"注册失败"})
                    }
                } else {
                    console.info('error:' + err.data);
                }
            }
        );
    },

    InputUsernameChange(event){
        this.user.username = event.value;
    },
    InputIphoneChange(event){
        this.user.phone=event.value;
    },
    InputPasswordChange(event){
        this.user.password = event.value;
    }
}